import request from '@/axios'
import type { UserLoginModel, UserLoginResult } from './types'
function formatRequestUri(name) {
  return 'hr/emplogin/' + name
}

export const userLogin = (data: UserLoginModel): Promise<IResponse<UserLoginResult>> => {
  const uri = formatRequestUri('EmpPwdLogin')
  return request.post({ url: uri, data })
}

export const loginOut = (): Promise<IResponse> => {
  return request.get({
    url: formatRequestUri('LoginOut')
  })
}

export function checkIsLogin() {
  return request.get({
    url: formatRequestUri('CheckIsLogin'),
    method: 'get'
  })
}

export function getLoginDatum() {
  return request.get({
    url: formatRequestUri('GetLoginDatum')
  })
}
export const checkIsVerCode = (name: string): Promise<IResponse<boolean>> => {
  return request.get({
    url: formatRequestUri('CheckIsVerCode'),
    params: {
      name
    }
  })
}

export function getVerCodeSrc(name) {
  const uri = request.getRequestUri('hr')
  return uri + formatRequestUri('CreateCode?name=' + name) + '&t=' + new Date().getTime()
}
